<template>
	<view class="mainbgc mainpadding">
		<view class="mainpadding ffffff radius flexbetween margin_top">
			<view class="flexleft">
				<view class="titletext">商品金额：</view>
				<view class="titletext qianshu">{{pricedata.return_price}}</view>
			</view>
			<view class="flexleft">
				<view class="titletext">消费积分：</view>
				<view class="titletext qianshu">{{pricedata.return_integral_price}}</view>
			</view>
		</view>
		<view class="mainpadding ffffff radius flexbetween margin_top" @click="cancelshow = true">
			<view class="titletext">申请原因</view>
			<view class="flexright">
				<input type="text" class="right margin_right" placeholder="请选择申请原因" disabled="" v-model="sqtk.name">
				<view class="right_icon"></view>
			</view>
		</view>
		<view class="mainpadding ffffff radius flexbetween margin_top">
			<view class="titletext">退款金额</view>
			<view class="qianshu ">
				<!-- ￥{{pricedata.return_price}} -->
				<input type="text" placeholder="请输入退款金额"  class="right margin_right" v-model="return_price">
			</view>
		</view>
		<view class="mainpadding ffffff radius flexbetween margin_top">
			<view class="titletext">退回积分</view>
			<view class="qianshu ">
				<!-- ￥{{pricedata.return_integral_price}} -->
				<input type="text" placeholder="请输入退回积分"  class="right margin_right" v-model="integral_price">
			</view>
		</view>
		<view class="mainpadding ffffff radius margin_top">
			<view class="titletext">申请说明</view>
			<textarea class="textareas margin_top" placeholder="请您详细填写申请说明" v-model="refund_content"></textarea>
		</view>
		<view class="mainpadding ffffff radius flexbetween margin_top" @click="phone(mobile)">
			<view class="titletext">联系电话</view>
			<view class="notitletext">{{mobile}}</view>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb" @click="submit">
			<view class="bottombtn">提交申请</view>
		</view>
		<!-- 申请退款原因列表 -->
		<quxiaolypop :messageInfo="{cancelshow:cancelshow,value:2}" @surecancel="surecancel"></quxiaolypop>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				lastmsg: {
					order_goods_id: "",
					order_id: "",
				},
				pricedata: {
					return_price: "", //退款金额
					return_integral_price: "" //退款积分

				},
				return_price:"",
				integral_price:"",
				cancelshow: false,
				sqtk: {
					name: "",
					id: "",
				},
				refund_content: "",
				mobile: "",

			}
		},
		onLoad(options) {
			this.lastmsg = JSON.parse(decodeURIComponent(options.msg));
			this.getprice()
			this.init()
		},
		methods: {
			phone(p) {
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {
					 
				})
			},
			init() {
				httpRequest.request('/api/index/getConfigInfo', 'POST', {}, false, false, true).then(res => {
					this.mobile = res.data.kf_mobile
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			surecancel(e) {
				this.sqtk = e
			},
			getprice() {
				httpRequest.request('/api/order/getReturnPrice', 'POST', {
					order_goods_id: this.lastmsg.order_goods_id
				}, false, false, true).then(res => {
					this.pricedata = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			submit() {
				if (this.sqtk.name == "") {
					httpRequest.toast("请选择申请原因");
					return false
				}
				if (this.refund_content == "") {
					httpRequest.toast("请填写申请说明");
					return false
				}
				if(this.integral_price == "" && this.return_price == ""){
					httpRequest.toast("退款金额和退回积分请至少填写一个");
					return false
				}
				httpRequest.modal('提示', '确定提交申请吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/order/addApply', 'POST', {
							order_goods_id: this.lastmsg.order_goods_id,
							order_id: this.lastmsg.order_id,
							reason: this.sqtk.name,
							refund_content: this.refund_content,
							integral_price:this.integral_price,
							return_price:this.return_price
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								setTimeout(() => {
									uni.navigateBack(1)
								}, 500)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.right {
		text-align: right;
	}

	.textareas {
		width: 100%;
		box-sizing: border-box;
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FD463E;
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}
</style>